package com.czl.base.data.bean.tengyun;

import android.os.Parcel;
import android.os.Parcelable;

import com.czl.base.data.bean.tengyun.ProductBean;
import com.czl.base.data.bean.tengyun.SortBean;

import java.io.Serializable;
import java.util.List;

/**
 * @author xubin
 * @date on 2019/6/19  14:05
 */
public class ReceiveBean implements Serializable, Parcelable {

    private static final long serialVersionUID = -1140609863615601069L;
    /**
     * dealtNum : 20
     * receiveId : 1
     * receiveCode : 001
     * receivePersonName : 王二
     * checkDate : 2019-01-01
     * receiveApprover : 张三
     * receiveComment : 领用说明
     */
    private int lendNum;
    private int returnNum;
    private int dealtNum;
    private int applyNum;
    private int receiveId;
    private int applyId;
    private int receivePersonId;
    private String receiveCode;
    private String receivePersonName;
    private String checkDate;
    private String receiveDate;
    private String returnDateStr12;
    private String returnDateStr8;
    private String applyDate;
    private String applyComment;
    private String receiveApprover;
    private String receiveComment;
    private String note;
    private String receiveName;
    private String approveUserName;
    private String receiveCompanyName;
    private String approveUserId;
    private String receivePersonDepartment;
    private String receiveOrganizationName;
    private String receiveTotalTextNum;
    private String returnComment;
    private String showName;
    private List<SortBean> sortList;
    private List<SortBean> receiveSortViewList;
    private List<ProductBean> receiveProductViewList;
    private int totalDamageNum;
    /**
     * date : 1588045787000
     * num : 2
     * userName : 李菁菁
     * userId : 42981
     */
    private long date;
    private int num;
    private String userName;
    private int userId;

    protected ReceiveBean(Parcel in) {
        lendNum = in.readInt();
        returnNum = in.readInt();
        dealtNum = in.readInt();
        applyNum = in.readInt();
        receiveId = in.readInt();
        applyId = in.readInt();
        receivePersonId = in.readInt();
        receiveCode = in.readString();
        receivePersonName = in.readString();
        checkDate = in.readString();
        receiveDate = in.readString();
        returnDateStr12 = in.readString();
        returnDateStr8 = in.readString();
        applyDate = in.readString();
        applyComment = in.readString();
        receiveApprover = in.readString();
        receiveComment = in.readString();
        note = in.readString();
        receiveName = in.readString();
        approveUserName = in.readString();
        receiveCompanyName = in.readString();
        approveUserId = in.readString();
        receivePersonDepartment = in.readString();
        receiveOrganizationName = in.readString();
        receiveTotalTextNum = in.readString();
        returnComment = in.readString();
        showName = in.readString();
        sortList = in.createTypedArrayList(SortBean.CREATOR);
        receiveSortViewList = in.createTypedArrayList(SortBean.CREATOR);
        receiveProductViewList = in.createTypedArrayList(ProductBean.CREATOR);
        totalDamageNum = in.readInt();
        date = in.readLong();
        num = in.readInt();
        userName = in.readString();
        userId = in.readInt();
    }

    public static final Creator<ReceiveBean> CREATOR = new Creator<ReceiveBean>() {
        @Override
        public ReceiveBean createFromParcel(Parcel in) {
            return new ReceiveBean(in);
        }

        @Override
        public ReceiveBean[] newArray(int size) {
            return new ReceiveBean[size];
        }
    };

    public String getShowName() {
        return showName == null ? "" : showName;
    }

    public String getShowName(String defaultValue) {
        return (showName == null ? defaultValue : showName);
    }

    public void setShowName(String showName) {
        this.showName = showName;
    }

    public String getReturnDateStr12() {
        return returnDateStr12;
    }

    public void setReturnDateStr12(String returnDateStr12) {
        this.returnDateStr12 = returnDateStr12;
    }

    public String getReturnDateStr8() {
        return returnDateStr8 == null ? "" : returnDateStr8;
    }

    public void setReturnDateStr8(String returnDateStr8) {
        this.returnDateStr8 = returnDateStr8;
    }

    public String getReturnComment() {
        return returnComment;
    }

    public void setReturnComment(String returnComment) {
        this.returnComment = returnComment;
    }

    public String getReceiveCompanyName() {
        return receiveCompanyName;
    }

    public void setReceiveCompanyName(String receiveCompanyName) {
        this.receiveCompanyName = receiveCompanyName;
    }

    public int getApplyId() {
        return applyId;
    }

    public void setApplyId(int applyId) {
        this.applyId = applyId;
    }

    public String getApproveUserId() {
        return approveUserId;
    }

    public void setApproveUserId(String approveUserId) {
        this.approveUserId = approveUserId;
    }

    public String getApproveUserName() {
        return approveUserName;
    }

    public void setApproveUserName(String approveUserName) {
        this.approveUserName = approveUserName;
    }

    public List<SortBean> getReceiveSortViewList() {
        return receiveSortViewList;
    }

    public void setReceiveSortViewList(List<SortBean> receiveSortViewList) {
        this.receiveSortViewList = receiveSortViewList;
    }

    public List<ProductBean> getReceiveProductViewList() {
        return receiveProductViewList;
    }

    public void setReceiveProductViewList(List<ProductBean> receiveProductViewList) {
        this.receiveProductViewList = receiveProductViewList;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getReceivePersonDepartment() {
        if (receivePersonDepartment == null || receivePersonDepartment.isEmpty()) {
            receivePersonDepartment = receiveOrganizationName;
        }
        return receivePersonDepartment == null ? "" : receivePersonDepartment;
    }

    public void setReceivePersonDepartment(String receivePersonDepartment) {
        this.receivePersonDepartment = receivePersonDepartment;
    }

    public String getReceiveOrganizationName() {
        return receiveOrganizationName;
    }

    public void setReceiveOrganizationName(String receiveOrganizationName) {
        this.receiveOrganizationName = receiveOrganizationName;
    }

    public String getReceiveDate() {
        if (receiveDate == null || receiveDate.isEmpty()) {
            receiveDate = applyDate;
        }
        return receiveDate;
    }

    public void setReceiveDate(String receiveDate) {
        this.receiveDate = receiveDate;
    }

    public String getApplyDate() {
        return applyDate;
    }

    public void setApplyDate(String applyDate) {
        this.applyDate = applyDate;
    }

    public String getApplyComment() {
        if (applyComment == null || applyComment.isEmpty()) {
            this.applyComment = getNote();
        }
        return applyComment == null ? "" : applyComment;
    }

    public void setApplyComment(String applyComment) {
        this.applyComment = applyComment;
    }

    public void setReceiveName(String receiveName) {
        this.receiveName = receiveName;
    }

    public List<SortBean> getSortList() {
        return sortList;
    }

    public void setSortList(List<SortBean> sortList) {
        this.sortList = sortList;
    }

    public int getLendNum() {
        return lendNum;
    }

    public void setLendNum(int lendNum) {
        this.lendNum = lendNum;
    }

    public int getApplyNum() {
        return applyNum;
    }

    public void setApplyNum(int applyNum) {
        this.applyNum = applyNum;
    }

    public int getReceivePersonId() {
        return receivePersonId;
    }

    public void setReceivePersonId(int receivePersonId) {
        this.receivePersonId = receivePersonId;
    }

    public int getDealtNum() {
        return dealtNum;
    }

    public void setDealtNum(int dealtNum) {
        this.dealtNum = dealtNum;
    }

    public int getReceiveId() {
        return receiveId;
    }

    public void setReceiveId(int receiveId) {
        this.receiveId = receiveId;
    }

    public String getReceiveCode() {
        return receiveCode;
    }

    public String getReceiveCode(String title) {
        return title + (receiveCode == null ? "" : receiveCode);
    }

    public String getReceiveCodeTitle(String title) {
        return title + (receiveCode == null ? "" : receiveCode);
    }

    public String getReceiveCodeNotNull() {
        return receiveCode == null ? "" : receiveCode;
    }

    public void setReceiveCode(String receiveCode) {
        this.receiveCode = receiveCode;
    }

    public String getReceivePersonName() {
        return receivePersonName;
    }

    public void setReceivePersonName(String receivePersonName) {
        this.receivePersonName = receivePersonName;
    }

    public String getCheckDate() {
        return checkDate;
    }

    public void setCheckDate(String checkDate) {
        this.checkDate = checkDate;
    }

    public String getReceiveApprover() {
        return receiveApprover;
    }

    public void setReceiveApprover(String receiveApprover) {
        this.receiveApprover = receiveApprover;
    }

    public int getReturnNum() {
        return returnNum;
    }

    public void setReturnNum(int returnNum) {
        this.returnNum = returnNum;
    }

    public String getReceiveComment() {
        return receiveComment;
    }

    public void setReceiveComment(String receiveComment) {
        this.receiveComment = receiveComment;
    }

    public long getDate() {
        return date;
    }

    public void setDate(long date) {
        this.date = date;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getUserId() {
        return userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    //计算总领用数量
    public static int getTotalReceiveNum(List<SortBean> list) {
        if (list == null) {
            return 0;
        }
        int total = 0;
        for (SortBean sortBean : list) {
            total += sortBean.getReceiveCount();
        }
        return total;
    }

    public boolean isVisibleNum(boolean visibleNum) {
        List<SortBean> sortList = getSortList();
        if (sortList == null || sortList.isEmpty()) {
            return false;
        }
        int total = 0;
        int totalApply = 0;
        for (SortBean sortBean : sortList) {
            Integer lendNum = sortBean.getLendNum();
            if (lendNum != null) {
                total += lendNum;
            }
            Integer applyNum = sortBean.getApplyNum();
            if (applyNum != null) {
                totalApply += applyNum;
            }
        }
        this.receiveTotalTextNum = total + "/" + totalApply;
        return visibleNum && total > 0;
    }

    public String getReceiveTotalTextNum(String title) {
        return title + " (" + receiveTotalTextNum + ")";
    }

    public boolean isRemandVisableNum(boolean visable) {
        return visable && returnNum > 0;
    }

    public String getRemandTotalTextNum(String title) {
        return title + " (" + returnNum + "/" + lendNum + ")";
    }

    public String getReceiveName() {
        if (receiveName == null || receiveName.isEmpty()) {
            receiveName = receivePersonName + "提交的领用单";
        }
        return receiveName;
    }

    public int getTotalDamageNumInt() {
        totalDamageNum = 0;
        List<SortBean> sortList = getSortList();
        if (sortList == null || sortList.isEmpty()) {
            return totalDamageNum;
        }
        for (SortBean sortBean : sortList) {
            Integer damageNum = sortBean.getDamageNum();
            if (damageNum != null) {
                totalDamageNum += damageNum;
            }
        }
        return totalDamageNum;
    }

    public int getTotalDamageNum() {
        return totalDamageNum;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(lendNum);
        dest.writeInt(returnNum);
        dest.writeInt(dealtNum);
        dest.writeInt(applyNum);
        dest.writeInt(receiveId);
        dest.writeInt(applyId);
        dest.writeInt(receivePersonId);
        dest.writeString(receiveCode);
        dest.writeString(receivePersonName);
        dest.writeString(checkDate);
        dest.writeString(receiveDate);
        dest.writeString(returnDateStr12);
        dest.writeString(returnDateStr8);
        dest.writeString(applyDate);
        dest.writeString(applyComment);
        dest.writeString(receiveApprover);
        dest.writeString(receiveComment);
        dest.writeString(note);
        dest.writeString(receiveName);
        dest.writeString(approveUserName);
        dest.writeString(receiveCompanyName);
        dest.writeString(approveUserId);
        dest.writeString(receivePersonDepartment);
        dest.writeString(receiveOrganizationName);
        dest.writeString(receiveTotalTextNum);
        dest.writeString(returnComment);
        dest.writeString(showName);
        dest.writeTypedList(sortList);
        dest.writeTypedList(receiveSortViewList);
        dest.writeTypedList(receiveProductViewList);
        dest.writeInt(totalDamageNum);
        dest.writeLong(date);
        dest.writeInt(num);
        dest.writeString(userName);
        dest.writeInt(userId);
    }
}
